package com.gduf.lsm.mapper;

import com.gduf.lsm.common.annotation.AutoFill;
import com.gduf.lsm.common.enums.OperationType;
import com.gduf.lsm.entity.Serve;
import org.apache.ibatis.annotations.Mapper;
import org.apache.ibatis.annotations.Select;
import org.apache.ibatis.annotations.Update;

import java.util.List;
import java.util.Map;

/**
 * @Author lsm
 * @Data
 * 养老服务-数据层接口
 */
@Mapper
public interface ServeMapper {
    /**
     * 新增
     * @param serve
     * @return
     */
    @AutoFill(value = OperationType.INSERT)
    int insert(Serve serve);

    /**
     * 删除
     * @param id
     * @return
     */
    int deleteById(Integer id);

    /**
     * 修改
     * @param serve
     * @return
     */
    @AutoFill(value = OperationType.UPDATE)
    int updateById(Serve serve);

    /**
     * 根据ID查询
     * @param id
     * @return
     */
    @Select("select * from serve where id=#{id}")
    Serve selectById(Integer id);

    /**
     * 查询所有
     * @param serve
     * @return
     */
    List<Serve> selectAll(Serve serve);

    /**
     * 查询是否有此养老服务名
     * @param name
     * @return
     */
    @Select("select * from serve where name=#{name}")
    Serve selectByName(String name);

    /**
     * 修改评价分数
     * @param serId
     * @param roundGrade
     */
    @Update("update serve set avg_grade=#{roundGrade} where id=#{serId}")
    void updateGradeById(Integer serId, float roundGrade);

    /**
     * 查询服务名及平均分
     * @return
     */
    @Select("select name,avg_grade from serve")
    List<Map<String, Double>> selectGrade();
}
